#pragma once

#include <string>
#include <vector>
#include <functional>
#include <cstdint>

#ifdef _WIN32
    #include <windows.h>
    #ifdef FILESCANNER_EXPORTS
        #define SCANNER_API __declspec(dllexport)
    #else
        #define SCANNER_API __declspec(dllimport)
    #endif
#else
    #define SCANNER_API
    typedef void* HANDLE;
    typedef struct {
        uint32_t dwLowDateTime;
        uint32_t dwHighDateTime;
    } FILETIME;
#endif

// 扫描结果结构
struct ScanResult {
    std::wstring filePath;
    uint64_t fileSize;
    FILETIME lastModified;
    
    ScanResult() : fileSize(0) {
        lastModified.dwLowDateTime = 0;
        lastModified.dwHighDateTime = 0;
    }
    
    ScanResult(const std::wstring& path, uint64_t size, const FILETIME& time)
        : filePath(path), fileSize(size), lastModified(time) {}
};

// 扫描状态枚举
enum class ScanStatus {
    Idle,
    Scanning,
    Completed,
    Cancelled,
    Error
};

// 回调函数类型定义
using ScanProgressCallback = std::function<void(const std::wstring& filePath, uint64_t fileSize, uint64_t totalFiles)>;
using ScanCompleteCallback = std::function<void(const std::vector<ScanResult>& results, ScanStatus status)>;

// C风格回调函数类型（用于DLL导出）
typedef void (*ProgressCallbackC)(const wchar_t* filePath, uint64_t fileSize, uint64_t totalFiles);
typedef void (*CompleteCallbackC)(const ScanResult* results, int count, int status);

// DLL导出的C接口
extern "C" {
    SCANNER_API HANDLE CreateScanner();
    SCANNER_API void DestroyScanner(HANDLE scanner);
    SCANNER_API bool StartScan(HANDLE scanner, const wchar_t* folderPath);
    SCANNER_API void StopScan(HANDLE scanner);
    SCANNER_API bool IsScanning(HANDLE scanner);
    SCANNER_API void SetProgressCallback(HANDLE scanner, ProgressCallbackC callback);
    SCANNER_API void SetCompleteCallback(HANDLE scanner, CompleteCallbackC callback);
    SCANNER_API int GetScanStatus(HANDLE scanner);
    SCANNER_API uint64_t GetTotalFilesScanned(HANDLE scanner);
    SCANNER_API uint64_t GetTotalBytesScanned(HANDLE scanner);
}